package com.sloth.bear.controller;

import com.sloth.bear.dto.base.ResponsePage;
import com.sloth.bear.dto.request.MomentListRequest;
import com.sloth.bear.dto.request.MomentRequest;
import com.sloth.bear.dto.vo.MomentVo;
import com.sloth.bear.dto.vo.MomentsFilterVo;
import com.sloth.bear.dto.vo.moments.CreatedTimeListVo;
import com.sloth.bear.service.MomentService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Moments控制器
 */
@RestController
@RequestMapping("/moments")
@RequiredArgsConstructor
public class MomentController {

    private final MomentService momentService;

    /**
     * 创建Moment
     */
    @PostMapping("/create")
    public Long createMoment(@RequestBody @Valid MomentRequest request) {
        return momentService.createMoment(request);
    }

    /**
     * Moment列表
     */
    @GetMapping("/list")
    public ResponsePage<MomentVo> listMoment(MomentListRequest request) {
        return momentService.listMoment(request);
    }

    /**
     * Moment详情
     */
    @GetMapping("/{id}")
    public MomentVo detailsMoment(@PathVariable Long id) {
        return momentService.detailsMoment(id);
    }

    /**
     * 更新Moment
     */
    @PutMapping("/{id}")
    public void updateMoment(@PathVariable Long id, @RequestBody MomentRequest request) {
        momentService.updateMoment(id, request);
    }

    /**
     * 获取过滤条件
     */
    @GetMapping("/filter")
    public MomentsFilterVo filter() {
        return momentService.filter();
    }

    /**
     * 删除Moment
     */
    @DeleteMapping("/{id}")
    public void deleteMoment(@PathVariable Long id) {
        momentService.deleteMoment(id);
    }

    /**
     * 随机获取一条Moment
     */
    @GetMapping("/random")
    public MomentVo randomMoment() {
        return momentService.randomMoment();
    }

    /**
     * 获取时间列表
     */
    @GetMapping("/created-time/list")
    public List<CreatedTimeListVo> listCreatedTime() {
        return momentService.listCreatedTime();
    }
}